package com.etc.common;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {

    // 第一个* 任意返回类void和有类型的方法
    // com.etc.service.* com.etc.service包下的任意类
    // .*(..)    任意方法，（。。）任意参数
    //  * *.*..*.*(..)
    @Pointcut("execution(* com.etc.service.*.*(..))")
    public void pointCut() {

    }

    @Before(value="pointCut()")
    public void before() {
        System.out.println("before: 加一块");
    }

    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        Object o = null;
        try {
            System.out.println("before收费1");
            o = joinPoint.proceed();;
            System.out.println("after收费1");
        } catch (Exception e) {
            System.out.println("Catch收费1");
            throw e;
        } finally {
            System.out.println("finally收费1");
        }
        return o;
    }
}
